// tge.rs
// copyright zipxing@hotmail.com 2022~2023

//! Context包装了一些公共变量
//! 封装stage，状态，输入事件等通用数据
//! state为了简便设计成u8，各个游戏实现可以采用独立设计的enum表示状态
//! context里还内置了一个随机数发生器rand方便使用
//! 也包含adapter渲染适配器
//! adapter是为了适应sdl和终端两种模式的绘制适配器

#[cfg(not(feature = "sdl"))]
use crate::render::adapter::cross::CrosstermAdapter;
#[cfg(feature = "sdl")]
use crate::render::adapter::sdl::SdlAdapter;
use crate::render::adapter::Adapter;
use crate::util::Rand;
use crossterm::event::Event;

pub struct Context {
    pub stage: u32,
    pub state: u8,
    pub rand: Rand,
    pub input_events: Vec<Event>,
    pub adapter: Box<dyn Adapter>,
}

impl Context {
    pub fn new() -> Self {
        Self {
            stage: 0,
            state: 0,
            rand: Rand::new(),
            input_events: vec![],
            #[cfg(feature = "sdl")]
            adapter: Box::new(SdlAdapter::new()),
            #[cfg(not(feature = "sdl"))]
            adapter: Box::new(CrosstermAdapter::new()),
        }
    }
}
